<template>
  <div>
    <x-header></x-header>
    <div class="x-work J-pos1">
      <x-banner :image="xworkImage"></x-banner>
      <div class="section section-1">
        <c-page-header title="WORK IN CHINA" subtitle="Characteristic teaching"></c-page-header>

        <div class="card">
          <div class="card--header">
            <transition-group name="fade" tag="div">
              <div key="0" class="clearfix" v-if="transObject.showCardTitle">
                <h1 class="card--title">arts</h1>
                <x-more-tag text="Sand painting" to=""></x-more-tag>
              </div>
              <p key="1" class="card--desc" v-if="transObject.showCardTitle">Sand painting has a unique charm of performance, can make the audience into the fantastic feeling and hitherto unknown visual enjoyment. Sand painting is enjoyable, natural, full of natural beauty, and, a fall, Yima, a hook, a pick, a beat.
              Practices are very expressive and appealing.</p>
            </transition-group name="fade" tag="div">

            <div class="swiper-art__wrap">
              <swiper class="swiper-art" :options="swiperOption" ref="coverSwiper">
                <swiper-slide>
                  <div class="swiper-slide">
                    <img src="../assets/arts/arts_slide1_1.jpg" alt="">
                  </div>
                </swiper-slide>
                <swiper-slide>
                  <div class="swiper-slide">
                    <img src="../assets/arts/arts_slide1_1.jpg" alt="">
                  </div>
                </swiper-slide>
                <div class="swiper-pagination clearfix" slot="pagination">
                  <div v-for="(dot, index) in artDotActive" @click="onArtDot(dot, index)" :style="{backgroundImage: 'url(' + dot.url + ')'}" :class="{'swiper-pagination__dot': true}"></div>
                </div>
              </swiper>

              <c-swiper-pointer :onPrev="onArtPrev" :onNext="onArtNext"
                prevClass="swiper--art-operate swiper--art-operate__prev"
                nextClass="swiper--art-operate swiper--art-operate__next"
                ></c-swiper-pointer>
            </div>
          </div>
        </div>
      </div>

      <div class="section section-2 J-pos2">
        <div>
          <transition name="fade-teach">
            <div class="clearfix" v-if="transObject.showTeach">
              <div class="banner">
                <img src="../assets/work/work_page_sport_section_banner.jpg" alt="Sport">
              </div>
              <div class="banner--desc">
                <h2 class="title">Sports</h2>
                <p class="pointer">Teaching</p>
                <p class="desc">Sand painting has a unique charm of performance, can make the audience into the fantastic feeling and hitherto unknown visual enjoyment. Sand painting is enjoyable, natural, full of natural beauty, and, a fall, Yima, a hook, a pick, a beat.
                  Practices are very expressive and appealing.</p>
              </div>
            </div>
          </transition>

          <div class="teach clearfix">
            <transition name="fade-teach">
              <div class="teach--desc" v-if="transObject.showTeach">
                <p class="teach--desc__text">ART</p>
                <p class="teach--desc__text">CULTURE</p>
                <p class="teach--desc__text">SPORTS</p>
                <p class="teach--desc__text">STUDY ABROAD</p>
                <p class="teach--desc__text">MANAGEMENT</p>
                <p class="teach--desc__text">ETC.</p>
              </div>
            </transition>
            <transition name="fade-slide">
              <ul class="teach--items clearfix" v-if="transObject.showTeachItems">
                <li :class="getTeachItemClass(item, index)" v-for="(item, index) in sports">
                  <img class="item__img" :src="item.image" alt="sports">
                  <p class="item__text">{{ item.desc }}</p>
                </li>
              </ul>
            </transition>
          </div>
        </div>
      </div>

      <div class="J-pos3">
        <transition name="fade-major">
          <div class="section section-3" v-if="transObject.showMajor">
            <div class="card">
              <div class="card--header">
                <div class="clearfix">
                  <h1 class="card--title">major clients</h1>
                  <x-more-tag text="teaching" to=""></x-more-tag>
                </div>
                <p class="card--desc">Sand painting has a unique charm of performance, can make the audience into the fantastic feeling and hitherto unknown visual enjoyment. Sand painting is enjoyable, natural, full of natural beauty, and, a fall, Yima, a hook, a pick, a beat.
                  Practices are very expressive and appealing.</p>
              </div>
            </div>

            <div class="swiper-major__wrap">
              <swiper class="swiper-major" :options="swiperOption" ref="majorSwiper">
                <swiper-slide>
                  <div class="swiper-slide">
                    <img class="slide__img" src="../assets/work/major_slide_1.jpg" alt="">
                    <p class="slide__text">Sand painting has a unique charm of performance, can make the audience into the fantastic feeling and hitherto unknown visual enjoyment. </p>
                  </div>
                </swiper-slide>
                <swiper-slide>
                  <div class="swiper-slide">
                    <img clas src="../assets/work/major_slide_1.jpg" alt="">
                    <p class="slide__text">Sand painting has a unique charm of performance.</p>
                  </div>
                </swiper-slide>
              </swiper>

              <div class="swiper-operate__wrap">
                <c-swiper-pointer :onPrev="onMajorPrev" :onNext="onMajorNext"
                  prevClass="swiper--major-operate swiper--major-operate__prev"
                  nextClass="swiper--major-operate swiper--major-operate__next"
                  ></c-swiper-pointer>
              </div>
            </div>
          </div>
        </transition>
      </div>
      <div class="section section-4" v-if="hackFooter"></div>

      <div class="c-path" v-if="transObject.showPath">
        <div :class="{'c-path--dot': true, active: item.active}"
          v-for="(item, index) in path"
          @click="toPath(item, index)">
          <span class="normal">
            <span class="text">{{ item.text }}</span>
            <i class="normal-icon"></i>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import $ from 'jquery'
  import { workSectionConfig } from '../config/workSectionConfig'
  import XHeader from '@/components/XHeader'
  import XBanner from '@/components/XBanner'
  import XMoreTag from '@/components/XMoreTag'
  import { swiper, swiperSlide } from 'vue-awesome-swiper'
  import CPageHeader from '@/components/CPageHeader'
  import CSwiperPointer from '@/components/CSwiperPointer'
  import { swiperDefaultConfig } from '../config/swiper.config'

  const { sports } = workSectionConfig
  const $window = $(window)

  export default {
    components: {
      CPageHeader,
      CSwiperPointer,
      swiper,
      swiperSlide,
      XHeader,
      XBanner,
      XMoreTag,
    },
    data() {
      return {
        path: [{
          active: true,
          text: 'arts china',
        }, {
          active: false,
          text: 'sports',
        }, {
          active: false,
          text: 'major clients',
        }],
        // 控制动画变量的动画
        hackFooter: false,
        transObject: {
          showPath: false,
          showCardTitle: false,
          showTeach: false,
          showTeachItems: false,
          showMajor: false,
        },
        sports,
        xworkImage: require('../assets/banner/xwork.jpg'),
        swiperOption: $.extend({}, swiperDefaultConfig, {
          autoplay: 3000,
        }),
        // slide dot
        artDotActive: [{
          url: require('../assets/arts/dot_1_1.png'),
          active: false
        }, {
          url: require('../assets/arts/dot_1_2.png'),
          active: false
        }, {
          url: require('../assets/arts/dot_1_3.png'),
          active: false
        }]
      }
    },
    mounted() {
      this.transObject.showCardTitle = true

      // 在当前位置刷新
      this.onShow()
      $window.on('scroll.section', e => {
        this.onShow()
      })

      // 锚点
      $window.on('scroll.path', e => {
        const top = $window.scrollTop();
        if(top > 375) {
          this.transObject.showPath = true
        } else {
          this.transObject.showPath = false
        }
      })
    },
    destroyed() {
      $window.off('scroll.section')
      $window.off('scroll.path')
    },
    computed: {
      swiper() {
        return this.$refs.coverSwiper.swiper
      },
      majorSwiper() {
        return this.$refs.majorSwiper.swiper
      }
    },
    methods: {
      // adapter
      onShow() {
        this.onShowTeach()
        this.onShowTeachItems()
        this.onShowMajor()
      },
      onShowTeachItems() {
        const top = this.getScrollTop()
        if(top >= 1600) {
          this.transObject.showTeachItems = true
        }
      },
      onShowTeach() {
        const top = this.getScrollTop()
        if(top >= 900) {
          this.transObject.showTeach = true
        }
      },
      onShowMajor() {
        const top = this.getScrollTop()
        if(top >= 1600) {
          this.transObject.showMajor = true
          this.hackFooter = true
          // 执行了最后一个就解绑
          $window.off('scroll.section')
        }
      },
      getScrollTop() {
        return $window.scrollTop()
      },
      getTeachItemClass(item, index) {
        return {
          item: true,
          [`item-${index}`]: true
        }
      },
      onArtDot(dot, index) {
        this.swiper.slideTo(index)
      },
      onArtPrev() {
        this.swiper.slidePrev();
      },
      onArtNext() {
        this.swiper.slideNext();
      },
      onMajorPrev() {
        this.majorSwiper.slidePrev();
      },
      onMajorNext() {
        this.majorSwiper.slideNext();
      },
      toPath(item, index) {
        let top = 0;

        switch(index) {
          case 0:
            top = this.getPathTop( $('.J-pos1') )
            break;
          case 1:
            top = this.getPathTop( $('.J-pos2') )
            break;
          case 2:
            top = this.getPathTop( $('.J-pos3') )
            break;
          default:
            top = this.getPathTop( $('.J-pos1') )
            break;
        }

        this.path.map((p, i) => {
          p.active = i === +index
          return p
        });

        $('html, body').stop(true, true).animate({
          scrollTop: top
        })
      },
      getPathTop($el) {
        // todo cache pos
        const offset = $el.offset()
        const top = offset.top

        return top
      },
    }
  }
</script>

<style lang="scss" scoped>
  .x-work {
    .c-path {
      &::after {
        height: 34px * 2;
      }
    }
  }

  .card {
    background: #fff;
  }

  .card--header {
    padding: 36px 110px 22px 60px;
  }

  .card--title {
    float: left;
    font-size: 83px;
    font-weight: 700;
  }

  .card--pointer {
    float: left;
    padding: 0 44px 0 20px;
    height: 32px;
    line-height: 32px;
    border: 3px #231815 solid;
    margin-top: 52px;
    margin-left: 16px;
  }

  .card--desc {
    line-height: 1.57;
    color: #515151;
  }

  .section-1 {
    max-width: 1380px;
    margin: 0 auto;
    margin-top: -326px;
    font-family: Montserrat;
    .x-more-tag {
      margin-top: 50px;
      margin-left: 13px;
    }
    .header {
      padding-left: 32px;
    }
    .header--title {
      font-size: 70px;
      font-weight: 700;
      color: #fff;
    }
    .header--subtitle {
      font-size: 21px;
      font-family: ClanPro;
      color: #fff;
    }
    .card {
      box-shadow: 0 36px 128px rgba(0, 0, 0, .3);
    }
    .card--header {
      padding-left: 110px;
    }
    .card--desc {
      margin-bottom: 20px;
    }
  }

  .section-2 {
    max-width: 1590px;
    height: 1328px;
    margin: 160px auto 0;
    .banner {
      float: left;
      width: 1095px;
      height: auto;
      border: 5px solid #fff;
      box-shadow: 10px 10px 50px rgba(0, 0, 0, .3);
      img {
        max-width: 100%;
        height: auto;
      }
    }
    .banner--desc {
      float: left;
      width: 300px;
      margin-left: 44px;
      padding-top: 100px;
      .title {
        font-size: 83px;
        font-weight: 700;
        font-family: Montserrat;
        color: #231815;
      }
      .pointer {
        font-family: ClanPro;
        border: 2px solid #231815;
        font-size: 19px;
        color: #231815;
        width: 154px;
        height: 26px;
        line-height: 26px;
        text-indent: 30px;
      }
      .desc {
        font-size: 14px;
        line-height: 22px;
        color: #515151;
        margin-top: 30px;
      }
    }
    .teach {
      position: relative;
      top: -234px;
    }
    .teach--desc {
      float: left;
      width: calc(100% - 860px);
      text-align: right;
      padding-top: 360px;
      padding-right: 22px;
      box-sizing: border-box;
    }
    .teach--desc__text {
      font-size: 24px;
      line-height: 28px;
      font-weight: 700;
      font-family: Montserrat;
      color: #353038;
      box-shadow: none;
    }
    .teach--items {
      width: 860px;
      float: right;
      margin-left: -3px;
      .item {
        width: 283px;
        margin-left: 3px;
        float: left;
        box-shadow: 0 30px 80px rgba(0, 0, 0, .3);
        position: relative;
      }
      .item-1 {
        z-index: 3;
      }
      .item-2 {
        z-index: 2;
      }
      .item__img {
        width: 100%;
        height: auto;
        display: block;
      }
      .item__text {
        font-size: 14px;
        text-align: right;
        background-color: #fff;
        padding: 12px 15px 28px 0;
      }

      transition: all 1.5s ease-in;
      &.fade-slide-enter-active .item,
      &.fade-slide-leave-active .item {
        transform: translate3d(0, 0, 0);
        opacity: 1;
        transition: all .7s;
      }
      &.fade-slide-enter .item,
      &.fade-slide-leave-to .item /* .fade-leave-active in <2.1.8 */ {
        transform: translate3d(0, 20px, 0);
        opacity: 0;
      }
      &.fade-slide-enter-active {
        .item-0 {
          transition-delay: 0s;
        }
        .item-1 {
          transition-delay: .5s;
        }
        .item-2 {
          transition-delay: 1s;
        }
      }
    }
  }

  .section-3 {
    width: 1370px;
    height: 1100px;
    margin: 0 auto;
    position: relative;
    .x-more-tag {
      margin-top: 50px;
      margin-left: 13px;
    }
    .slide__img {
      max-width: 100%;
      height: auto;
    }
    .slide__text {
      height: 106px;
      line-height: 106px;
      color: #515151;
      font-size: 14px;
      background: #fff;
      text-indent: 40px;
    }
  }

  .section-4 {
    height: 340px;
    background: #353038;
    margin-top: -340px;
  }


  /* art slide */

  .swiper-art {
    padding-bottom: 166px;
    .swiper-pagination {
      margin-top: 36px;
      width: 385px;
      left: 50%;
      margin-left: -192px;
    }
    .swiper-pagination__dot {
      cursor: pointer;
      width: 123px;
      height: 82px;
      float: left;
      margin-left: 8px;
      &:first-child {
        margin-left: 0;
      }
    }
  }

  .swiper-art__wrap,
  .swiper-major__wrap {
    position: relative;
  }

  .swiper-operate__wrap {
    position: absolute;
    bottom: 30px;
    right: 36px;
    z-index: 1;
  }

  .fade-enter-active,
  .fade-leave {
    opacity: 1;
    transition: all 2s;
  }
  .fade-enter,
  .fade-leave-active {
    opacity: 0;
    transition: all 2s;
  }

  .fade-teach-enter-active,
  .fade-teach-leave {
    opacity: 1;
    transition: all 3s;
  }
  .fade-teach-enter,
  .fade-teach-leave-active {
    opacity: 0;
    transition: all 3s;
  }

  .fade-major-enter-active,
  .fade-major-leave {
    opacity: 1;
    transition: all 2.2s;
  }
  .fade-major-enter,
  .fade-major-leave-active {
    opacity: 0;
    transition: all 2.2s;
  }

  @media only screen and (max-width: 1670px) {
    .section-2 {
      height: 1300px;
      .banner {
        max-width: 60%;
      }
      .banner--desc {
        width: 30%
      }
      .teach {
        top: -130px;
      }
    }
  }
  @media only screen and (max-width: 1500px) {
    .section-2 {
      height: 1200px;
    }
  }
  @media only screen and (max-width: 1500px) {
    .section-2 {
      height: 1160px;
    }
  }
  @media only screen and (max-width: 1340px) {
    .section-2 {
      height: 1120px;
      .teach {
        top: -100px;
      }
    }
  }
</style>
